Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset rounding for odd-sized tiles #74773

Closed

Conversation

Portponky
Copy link

@Portponky Portponky commented Mar 11, 2023

Bug: #62911

The issue had two causes.

  1. The quadrant provides coordinates from the center of the first tile as a float (so with a .5), then subtracted the tile origin as an integer (rounded down). If the tile position is floored before drawing the tile, this fixes the offset.
  2. Negative signed quadrants were positioned by truncating their coordinates in the map_to_local hashmap, causing them to be rounded towards zero. This needs to be floored to prevent a 1 pixel offset for quadrants positioned behind 0,0.

Bugsquad edit:

@Portponky Portponky requested a review from a team as a code owner March 11, 2023 15:28
@kleonc
Copy link
Member

kleonc commented Mar 11, 2023

Have you tested it with non-square tiles?

@Portponky
Copy link
Author

Have you tested it with non-square tiles?

Yep, looks good:
image

@kleonc
Copy link
Member

kleonc commented Mar 11, 2023

Yep, looks good:

I could have been more precise, I meant non-square tile shape. Or more specifically all different combinations of tile shape/layout/offset_axis settings:
Godot_v4 0-stable_win64_mzXwlwP3sq

@Portponky
Copy link
Author

32x16 isometric
image

16x5 isometric
image

5x5 hexagon
image

Layout/offset axis do not change the outcome.

In these cases, the positioning is closer to the intended than with 4.0 stable. Whether or not the exact pixel positioning is correct or not is probably another issue, as it is enforced by draw_tile taking an integer tile position.

@kleonc
Copy link
Member

kleonc commented Mar 11, 2023

16x5 isometric image

This shows it doesn't work properly: the tile on the right has incorrect position, it should be 0.5 unit upwards (X axis should go through its middle).

5x5 hexagon image

This shows it doesn't work properly: for these 3 rows of tiles the middle row should be exactly in between the two other rows rows (both overlaps should be 1.5 unit in height).


MRP from #62911 (comment) with this PR:

godot windows editor x86_64_nVx0TOHYWq FBUPq5znSU

As you can see the the in-editor grid is drawn properly as it's aligned with the (0, 0) cell (the green one) which is properly aligned with the X/Y axes. It's the tiles with odd Y coordinate being rendered incorrectly (like the white one).

BTW what I've suggested in #62911 (comment) has the exact same issue.

@Portponky
Copy link
Author

That's because the tilemap composes all the tiles in the quadrant using integer coordinates. Perhaps it would be a better change to alter that behaviour.

@Portponky
Copy link
Author

Hmm, after having a poke around, it seems it would be a major change to place tiles at non-integer coordinates. The quadrants and related placement data are all coded based on integer coordinates.

@kleonc
Copy link
Member

kleonc commented Mar 12, 2023

Hmm, after having a poke around, it seems it would be a major change to place tiles at non-integer coordinates. The quadrants and related placement data are all coded based on integer coordinates.

Indeed, seems like that's the exact cause. Doesn't seem like a major change, it's an actual bug, the local positions shouldn't be truncated to ints in there. I'll open a PR.

@Chaosus Chaosus added this to the 4.1 milestone Mar 12, 2023
@Portponky
Copy link
Author

Great work, closing.

@Portponky Portponky closed this Mar 12, 2023
@clayjohn clayjohn removed this from the 4.1 milestone Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TileMap misaligned with odd numbers
5 participants